package crm.view.funktionBar;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JPanel;

import crm.model.teacherPC.Manager;
import crm.view.funktionBar.listener.InternetStopListener;


public class FunktionBar extends JPanel{
	Manager manager;
	public JButton orderBut;
	public JButton LockBut;
	public JButton inetBut;
	private JButton btnApplicationenSperren;
	private JButton btnVnc;

	public FunktionBar(Manager manager) {
		this.manager = manager;

		createGUI();
	}

	private void createGUI() {


		setLayout(new BorderLayout());
		Box funktionBox = Box.createHorizontalBox();
		add(funktionBox, BorderLayout.CENTER);
		{
			orderBut = new JButton();
			orderBut.setBorderPainted(false);
			funktionBox.add(orderBut);
			orderBut.setText("neu Anordnen");
		}
		{
			LockBut = new JButton();
			LockBut.setBorderPainted(false);
			funktionBox.add(LockBut);
			LockBut.setText("Alle Sperren");
		}
		{
			inetBut = new JButton();
			inetBut.setBorderPainted(false);
			funktionBox.add(inetBut);
			inetBut.setText("Internet Sperren");
			{
				btnApplicationenSperren = new JButton("Applicationen Sperren");
				btnApplicationenSperren.setBorderPainted(false);
				btnApplicationenSperren.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent ev) {
						JButton but = (JButton)ev.getSource();
						if (but.getActionCommand().equals("Applicationen Sperren")){
							for(int i = 0; i< manager.getStudentCount(); i++){
								manager.getStudent(i).setAppCloseOn(true);
							}
							but.setText("Application Sperrung aufheben");
						}else if (but.getActionCommand().equals("Application Sperrung aufheben")){
							for(int i = 0; i< manager.getStudentCount(); i++){
								manager.getStudent(i).setAppCloseOn(false);
							}
							but.setText("Applicationen Sperren");
						}
					}
				});
				funktionBox.add(btnApplicationenSperren);
			}
			{
				btnVnc = new JButton("VNC");
				btnVnc.setBorderPainted(false);
				btnVnc.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						ProcessBuilder p = new ProcessBuilder(new String[]{"java" , "-jar", "vncviewer.jar"});
						
						try {
							p.start();
						} catch (IOException ex) {
							// TODO Auto-generated catch block
							ex.printStackTrace();
						}
					}
				});
				funktionBox.add(btnVnc);
			}
			inetBut.addActionListener(new InternetStopListener(manager));
		}
	}


}
